package com.lamatek.tags.google;

import java.io.Serializable;
import java.util.Vector;

import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

/**
 * GoogleMapInfoWindowTabbedTag
 * 
 * This tag represents a &lt;googlemaps:tabbedInfoWindow> tag. It is like an info window, 
 * but can display multiple panels of information through use of a tabbed interface.
 * 
 * Developers should not extend this class or override it's methods.
 * 
 * @author Tom Cole
 * @version 0.87
 */
public class GoogleMapInfoWindowTabbedTag extends BodyTagSupport implements Serializable, InfoWindow {

    boolean display = false;
    Vector tabs = null;
    String style = null;
    String css_class = null;
    /**
     * Overrides doStartTag from BodyTagSupport.
     */
    public int doStartTag() {
        return EVAL_BODY_INCLUDE;
    }
    /**
     * Overrides doEndTag from BodyTagSupport.
     */
    public int doEndTag() {
        Tag tag = this;
        while (tag.getParent() != null) {
            if (tag.getParent() instanceof GoogleMapMarkerTag) {
                ((GoogleMapMarkerTag) tag.getParent()).setInfoWindow(this);
                return EVAL_PAGE;
            }
            tag = tag.getParent();
        }
        return EVAL_PAGE;
    }
    /**
     * Adds a tab to this tabbed info window.
     * 
     * @param tab An initialized GoogleMapTabTag
     */
    public void addTab(GoogleMapTabTag tab) {
        if (tabs == null)
            tabs = new Vector();
        tabs.addElement(tab);
    }
    /**
     * Returns the number of tabs that have been added to this tabbed info window.
     * 
     * @return The number of tabs in this info window.
     */
    public int getTabCount() {
        if (tabs == null)
            return 0;
        else
            return tabs.size();
    }
    /**
     * Returns the tab that is stored at the given location.
     * 
     * @return A GoogleMapTabTag or null of none exists at the specified location.
     */
    public GoogleMapTabTag getTab(int i) {
        if (tabs == null)
            return null;
        else 
            return (GoogleMapTabTag) tabs.elementAt(i);
    }
    /**
     * Inherited from the InfoWindow interface. Denotes this as a tabbed info window.
     * 
     * @return true.
     */
    public boolean isTabbed() {
        return true;
    }
    /**
     * Denotes whether or not this info window should be displayed as soon as the
     * map is loaded. If set to false, the user will need to click the marker
     * to display the tabbed info window.
     * 
     * @return True or false.
     */
    public boolean isDisplay() {
        return display;
    }
    /**
     * Sets whether or not this info window should be displayed as soon as the
     * map is loaded. If set to false, the user will need to click the marker
     * to display the tabbed info window.
     * 
     * @param display True or false.
     */
    public void setDisplay(boolean display) {
        this.display = display;
    }
    /**
     * Gets the css style attribute for this window's content.
     * 
     * @return The CSS style attribute(s)
     */
    public String getStyle() {
        return style;
    }
    /**
     * Sets the css style attribute for this window's content.
     * 
     * @param style CSS style attribute(s)
     */
    public void setStyle(String style) {
        this.style = style;
    }
    /**
     * Gets the css class attribute for this window's content.
     * 
     * @return The CSS class attribute(s)
     */
    public String getCss_class() {
        return css_class;
    }
    /**
     * Sets the css style attribute for this window's content.
     * 
     * @param style CSS style attribute(s)
     */
    public void setCss_class(String css_class) {
        this.css_class = css_class;
    }
}
